package com.example.haojiutao.service.impl;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.mapper.AdminMapper;
import com.example.haojiutao.model.domain.Admin;
import com.example.haojiutao.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Description:
 * @Author: wang_meiying
 * @CreateTime: 2024/1/27 19:25
 */
@Slf4j
@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    /*
     * @Description: 新增
     * @Author: wang_meiying
     * @CreateTime: 2024/1/27 19:27
     * @param: user
     * @return: int
     */
    @Override
    public Result insert(Admin admin) {

        int rows = adminMapper.insert(admin);
        if(rows == 1){
            return Result.success("成功！");
        }
        return Result.faile("失败");
    }

    @Override
    public Admin selectById(Integer adminId) {
        Admin admin = adminMapper.selectById(adminId);
        log.info("admin的信息为:{}",admin);
        return admin ;
    }

    @Override
    public Result adminInfoUpdate(Admin admin){

        //2.封装数据，插入数据库userMapper.insert(user)
        int rows = adminMapper.adminInfoUpdate(admin);
        if(rows == 1){
            return Result.success("修改成功！");

        }
        return Result.faile("修改失败");
    }

    @Override
    public Result deleteById(Integer adminId) {
        Admin admin = new Admin();
        admin.setAdminId(adminId);
        admin.setDelFlag(1);
        int rows = adminMapper.updateDeleteFlagById(admin);
        if(rows == 1){
            return Result.success("删除成功！");
        }
        return Result.faile("删除失败");

    }



}

